package com.blobfish.fiction.common.download;

import com.jfinal.log.Log;

public class AddDownloadTaskThread extends Thread {
    private static final Log log = Log.getLog(AddDownloadTaskThread.class);
    private final DownloadQueue downloadQueue;
    private final String bookNo;
    private final boolean isBreakpointDownload;

    /**
     * 构造方法
     * @param name 下载线程名称
     * @param downloadQueue 下载任务队列
     */
    public AddDownloadTaskThread(String name, String bookNo, DownloadQueue downloadQueue) {
        super(name);
        this.downloadQueue = downloadQueue;
        this.bookNo = bookNo;
        this.isBreakpointDownload = false;
    }

    /**
     * 构造方法
     * @param name 下载线程名称
     * @param downloadQueue 下载任务队列
     */
    public AddDownloadTaskThread(String name, String bookNo, DownloadQueue downloadQueue, boolean isBreakpointDownload) {
        super(name);
        this.downloadQueue = downloadQueue;
        this.bookNo = bookNo;
        this.isBreakpointDownload = isBreakpointDownload;
    }

    @Override
    public void run() {
        try {
            if (isBreakpointDownload) {
                this.downloadQueue.putBreakpointDownload(bookNo);
            } else {
                this.downloadQueue.put(bookNo);
            }
        } catch (InterruptedException e) {
            log.error(e.getMessage());
        }
    }
}
